<?php


namespace App\Filters;


class LoginFilter
{
    public static function filter()
    {
        if (empty($_POST['username'])) {
            return array('code' => 0,'message' => '用户名不能为空');
        }
        if (strlen($_POST['username']) > 11) {
            return array('code' => 0,'message' => '用户名长度不能超过11个字符');
        }
        if (!preg_match('/^[a-zA-Z]([a-zA-Z0-9]){1,10}$/', $_POST['username'])) {
            return array('code' => 0,'message' => '用户名只能是字母和数字');
        }

        if (empty($_POST['password'])) {
            return array('code' => 0,'message' => '密码不能为空');
        }
        if (!preg_match('/^[a-zA-Z\d_]{6,}$/', $_POST['password'])) {
            return array('code' => 0,'message' => '密码必须是字母和数字');
        }

        $_POST['username'] = htmlspecialchars($_POST['username'],ENT_QUOTES);
        return true;
    }
}